package com.git.bds.mr.patient.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.git.bds.mr.patient.convert.PatientConvert;
import com.git.bds.mr.patient.model.dto.PatientDTO;
import com.git.bds.mr.patient.model.domain.PatientInfo;
import com.git.bds.mr.patient.service.PatientInfoService;
import com.git.bds.mr.patient.model.vo.PatientVO;
import com.git.bds.mr.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户个人信息表 前端控制器
 * </p>
 *
 * @author 成大事
 * @since 2022-09-23 17:55:22
 */
@Api(tags = "患者 管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/patient")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PatientInfoController {

    private final PatientInfoService patientInfoService;

    @PostMapping("/getSelfInfo")
    @ApiOperation("获取患者个人详细信息")
    public R<PatientVO> getSelfInfo(){
        PatientInfo info = patientInfoService.getById(StpUtil.getLoginIdAsLong());
        return R.ok(PatientConvert.INSTANCE.toPatientVO(info));
    }


    @PostMapping("/updateSelfInfo")
    @ApiOperation("患者修改个人详细信息")
    public R<Boolean> updateSelfInfo( PatientDTO patientDTO){
        return R.decide(patientInfoService.updateSelfInfo(patientDTO));
    }



}
